#include <iostream>
#include <cstdlib>
using namespace std;
int commonDivisor(int x1, int x2)
{
	int minnum = min(x1, x2);
	while (minnum > 1) {
		if (x1 % minnum != 0 || x2 % minnum != 0)    minnum--;
		else break;
	}
	return minnum;
}
int commonDivisor(int x1, int x2, int x3)
{
	return commonDivisor(commonDivisor(x1, x2), x3);
}
int commonDivisor(int x1, int x2, int x3, int x4)
{
	return commonDivisor(commonDivisor(x1, x2, x3), x4);
}
int main()
{
	int a, b, c, d;
	int count;
	cout << "请输入整数的个数(2/3/4): ";
	cin >> count;
	if (count == 2) {
		cout << "请输入2个整数:";
		cin >> a >> b;
		cout << "整数" << a << "," << b << " 的最大公约数为: " << commonDivisor(a, b) << endl;
	}
	else if (count == 3) {
		cout << "请输入3个整数:";
		cin >> a >> b >> c;
		cout << "整数" << a << "," << b << "," << c << " 的最大公约数为: " << commonDivisor(a, b, c) << endl;
	}
	else if (count == 4) {
		cout << "请输入4个整数:";
		cin >> a >> b >> c >> d;
		cout << "整数" << a << "," << b << "," << c << "," << d << " 的最大公约数为: " << commonDivisor(a, b, c, d) << endl;
	}
	else {
		cout << "非法输入！" << endl;
	}
	system("pause");
	return 0;
}